home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / os2 / cenv2_19.arj / WINSET.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  5KB  |  161 lines

  1. EXTPROC CEnvi
  2. /*********************************************************
  3.  *** WinSet.cmd - CEnvi program to position, maximize, ***
  4.  *** ver.1        or hide a window, etc...             ***
  5.  *********************************************************/
  6.  
  7. #include <PMdll.lib>
  8. #include <WinTools.lib>
  9.  
  10. #define  NO_ERROR          0     // return code from most successful DosCalls
  11.  
  12. // Initialize an array of Commands, their functions, and how many extra
  13. // arguments they require
  14. commands = { { "MIN",      "MyMinimizeWindow",     "0" },
  15.              { "MAX",      "MyMaximizeWindow",     "0" },
  16.              { "RESTORE",  "MyRestoreWindow",      "0" },
  17.              { "HIDE",     "MyHideWindow",         "0" },
  18.              { "SHOW",     "MyShowWindow",         "0" },
  19.              { "ACTIVE",   "MyActivateWindow",     "0" },
  20.              { "INACTIVE", "MyInactivateWindow",   "0" },
  21.              { "CLOSE",    "MyClose",              "0" },
  22.              { "SIZE",     "MySizeWindow",         "2" },
  23.              { "MOVE",     "MyMoveWindow",         "2" },
  24.              { "BIGGEST",  "MakeBiggestWindow",    "0" } };
  25.  
  26. main(argc,argv)
  27. {
  28.    if ( argc < 3  ||  !strcmp(argv[1],"/?")  ||  !strcmpi(argv[1],"help") ) {
  29.       Instructions();
  30.    } else if ( argc == 4  &&  !stricmp(argv[2],"TITLE") ) {
  31.       SetWindowTitle(GetHwnd(argv[1]),argv[3]);
  32.    } else {
  33.       // find the command in list of commands we know
  34.       for ( i = GetArraySpan(commands); 0 <= i; i-- ) {
  35.          command = commands[i];
  36.          if ( !stricmp(argv[2],commands[i][0]) )
  37.             break;
  38.       }
  39.       if ( i < 0  ||  argc != 3 + (ArgCount = atoi(command[2])) ) {
  40.          Instructions();
  41.       } else {
  42.          // build array of args
  43.          for ( i = 0; i < ArgCount; i++ )
  44.             Args[i] = atoi(argv[3+i]);
  45.          // send command to window
  46.          function(command[1],argv[1],
  47.                   Args[0],Args[1],Args[2],Args[3],Args[4],
  48.                   Args[5],Args[6],Args[7],Args[8],Args[9]);
  49.       }
  50.    }
  51. }
  52.  
  53. Instructions()
  54. {
  55.    printf("\a\n")
  56.    printf("WinSet - Tell a window where to go\n")
  57.    printf("\n")
  58.    printf("SYNTAX: WinSet Title MIN\n")
  59.    printf("        WinSet Title MAX\n")
  60.    printf("        WinSet Title HIDE\n")
  61.    printf("        WinSet Title SHOW\n")
  62.    printf("        WinSet Title RESTORE\n")
  63.    printf("        WinSet Title BIGGEST\n")
  64.    printf("        WinSet Title ACTIVE\n")
  65.    printf("        WinSet Title INACTIVE\n")
  66.    printf("        WinSet Title CLOSE\n")
  67.    printf("        WinSet Title SIZE Width Height\n")
  68.    printf("        WinSet Title MOVE Column Row\n")
  69.    printf("        WinSet Title TITLE NewTitle\n")
  70.    printf("\n")
  71.    printf("   Where: Title - All or partial name of a Window\n")
  72.    printf("\n");
  73.    printf("EXAMPLE: WinSet \"OS/2 Window\" MOVE 300 200\n");
  74.    printf("         WinSet \"Drive C\" TITLE \"Boot Drive\"\n")
  75.    printf("\n")
  76. }
  77.  
  78. MyMinimizeWindow(WinSpec)
  79. {
  80.    ShowWindow(GetHwnd(WinSpec),SW_MINIMIZE);
  81. }
  82.  
  83. MyMaximizeWindow(WinSpec)
  84. {
  85.    ShowWindow(GetHwnd(WinSpec),SW_SHOWMAXNOACTIVE);
  86. }
  87.  
  88. MyHideWindow(WinSpec)
  89. {
  90.    ShowWindow(GetHwnd(WinSpec),SW_HIDE);
  91. }
  92.  
  93. MyShowWindow(WinSpec)
  94. {
  95.    ShowWindow(GetHwnd(WinSpec),SW_SHOWNOACTIVATE);
  96. }
  97.  
  98. MyRestoreWindow(WinSpec)
  99. {
  100.    ShowWindow(GetHwnd(WinSpec),SW_RESTORENOACTIVE);
  101. }
  102.  
  103. MySizeWindow(WinSpec,Width,Height)
  104. {
  105.    SetSize(GetHwnd(WinSpec),Width,Height);
  106. }
  107.  
  108. MyMoveWindow(WinSpec,Column,Row)
  109. {
  110.    SetPosition(GetHwnd(WinSpec),Column,Row);
  111. }
  112.  
  113. MyActivateWindow(WinSpec)
  114. {
  115.    if ( 0 != (_handle = GetHwnd(WinSpec)) )
  116.       SetActiveWindow(_handle);
  117. }
  118.  
  119. MyActivateWindow(WinSpec)
  120. {
  121.    if ( 0 != (_handle = GetHwnd(WinSpec)) )
  122.       SetActiveWindow(_handle);
  123. }
  124.  
  125. MyInactivateWindow(WinSpec)
  126. {
  127.    if ( 0 != (_handle = GetHwnd(WinSpec)) )
  128.       SetWindowPos(_handle,0,0,0,0,0,SWP_DEACTIVATE);
  129. }
  130.  
  131. MyClose(WinSpec)
  132. {
  133.    if ( !(_handle = GetHwnd(WinSpec)) )
  134.       return(FALSE);
  135.    #define WM_CLOSE  0x0029
  136.    #define WM_QUIT   0x002a
  137.    WinPostMsg(_handle,WM_QUIT,0,0,False);
  138.    return(TRUE);
  139. }
  140.  
  141. MakeBiggestWindow(WinSpec)
  142. {
  143.    if ( !(_handle = GetHwnd(WinSpec)) )
  144.       return(FALSE);
  145.    ShowWindow(_handle,SW_SHOWMAXNOACTIVE);
  146.    // get maximized size, then restore but at maximum size
  147.    GetWindowRect(_handle,rect);
  148.    ShowWindow(_handle,SW_RESTORENOACTIVE);
  149.    SetWindowRect(_handle,rect);
  150. }
  151.  
  152. GetHwnd(pWinSpec)
  153. {
  154.    // Try to find window handle, look for exact match first and then
  155.    // partial match if exact not found.  Return 0 if problem.
  156.    if ( !(lHwnd = GetWindowHandle(pWinSpec,True)) )
  157.       lHwnd = GetWindowHandle(pWinSpec);
  158.    return lHwnd;
  159. }
  160.  
  161.